document.writeln("<style type=\"text/css\">");
document.writeln("@import url(\"css/marqueeBar.css\");");
document.writeln("</style>");

var __scrollBarControl = null;
/**
 * 滚动栏对象
 * @param marqueeId 滚动内容DIV对象的ID
 * @param dispalyNum 显示条数
 */
function marqueeBarVO(marqueeId,dispalyNum)
{	
	__scrollBarControl = this;
	this.marqueeBox = document.getElementById(marqueeId);	//获得滚动框对象
	this.marqueeInterval=new Array(); //定义滚动延迟时间
	this.marqueeContent = new Array();	//缓存内容数组
	this.sourceCount;	//原内容的个数
	this.marqueeCount;	//计算后内容个数	
	this.dispalyNum = Math.max(1,dispalyNum);	//显示个数
	this.direction;	//滚动的方向：up,down,left,right
	this.marqueeId=0;
	this.marqueeDelay=4000;	//延迟
	this.marqueeHeight;	//滚动栏高度，默认为一个栏的高度
}


/**
 * 初始化

 */
marqueeBarVO.prototype.initMarquee = function() 
{    
    if(this.marqueeBox==null)
    {
    	sl_alert("对象不存在！");
    	return;
    }	
    var ul = this.marqueeBox.firstChild;	//获得UL对象	
    var liArray = ul.childNodes;	//获得实际内容列表
    this.sourceCount = liArray.length; 
    if(this.sourceCount<=0)	//如果没有内容则什么都不做
    	return;
    this.marqueeCount = parseInt(this.sourceCount/this.dispalyNum);//计算循环个数
    if(this.sourceCount%this.dispalyNum>0)
    	this.marqueeCount++;
    this.marqueeHeight = liArray[0].offsetHeight*this.dispalyNum; //显示的高度,由单条内容的高度乘以显示个数得到   
    for(i=0;i<this.sourceCount;i++)
    {    	
    	this.marqueeContent[i] = liArray[i].innerHTML;
    }
    ul.innerHTML = "";	//清空内容   
    
    // 设置样式 
    this.marqueeBox.style.height = this.marqueeHeight; 
    //创建显示内容的DIV 	
    var nextLine = document.createElement('DIV');       
    var str = "";//定义显示内容,将一次需要显示的内容存到显示内容中去     
	for(i=0;i<this.dispalyNum;i++)		
	{
		if(i<this.sourceCount)
		{		
			str +=  "<li>" + this.marqueeContent[i]+"</li>";					
		}		
	}    
    nextLine.innerHTML = str;
    ul.appendChild(nextLine);
    if(this.sourceCount<=this.dispalyNum)//内容大于每次显示个数才进行滚动
    	return;
    //增加滚动处理	
    this.marqueeBox.onmouseover = function() {clearInterval(__scrollBarControl.marqueeInterval[0]);};
    this.marqueeBox.onmouseout = function() {__scrollBarControl.marqueeInterval[0] = setInterval(function(){__scrollBarControl.startMarquee()},this.marqueeDelay);};
    
   	this.marqueeId++;    	
    this.marqueeInterval[0] = setInterval(function(){__scrollBarControl.startMarquee()},this.marqueeDelay);   
}

marqueeBarVO.prototype.startMarquee = function() 
{    
    if(this.marqueeId>=this.marqueeCount) this.marqueeId=0;
    var ul = this.marqueeBox.firstChild;	//获得UL对象	
    var liArray = ul.childNodes;	//获得实际内容列表    	      
    if(liArray.length==1) 
    {
        var str = "";//定义显示内容,将一次需要显示的内容存到显示内容中去
		for(i=0;i<this.dispalyNum;i++)		
		{
			var index = i + this.dispalyNum*this.marqueeId;
			
			if(index<this.sourceCount)
			{		
				str +=  "<li>" + this.marqueeContent[index]+"</li>";					
			}
			else
				str += 	"<li>&nbsp;</li>";				
		} 
        var nextLine = document.createElement('DIV');	                
	    nextLine.innerHTML = str;
        ul.appendChild(nextLine);
    }
    else 
    {    	
        var str = "";//定义显示内容,将一次需要显示的内容存到显示内容中去     
		for(i=0;i<this.dispalyNum;i++)		
		{
			var index = i + this.dispalyNum*this.marqueeId;
			if(index<this.sourceCount)
			{		
				str +=  "<li>" + this.marqueeContent[index]+"</li>";					
			}
			else
				str += 	"<li>&nbsp;</li>";		
		} 

        liArray[0].innerHTML=str;
        ul.appendChild(liArray[0]);
        this.marqueeBox.scrollTop=0;        
    }
    this.marqueeId++;  
    clearInterval(this.marqueeInterval[1]);
    this.marqueeInterval[1] = setInterval(function(){__scrollBarControl.scrollMarquee()},30);
}

marqueeBarVO.prototype.scrollMarquee = function() 
{  
    	this.marqueeBox.scrollTop++;     
	    if(this.marqueeBox.scrollTop%this.marqueeHeight==0){  
	        clearInterval(this.marqueeInterval[1]);        
	    }
}